﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

public partial class WorkTimeN_WorkOnTypeGroup : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitializeComponent(true);

            Master.DataSource = WMaster;



            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "";
            master.PageName = "考勤类型分组设置";
            master.PicUrl = "";
            master.IntiBar();


            if (ddlWorkOnType.Items.Count <= 0)
            {
                ddlWorkOnType.Items.Add(new ListItem("所有人员", "AB"));
                ddlWorkOnType.Items.Add(new ListItem("未绑定人员", "NB"));
                foreach(DataRow dr in wdsWorkType.View.Table.Rows)
                {
                    ddlWorkOnType.Items.Add(new ListItem(dr["GroupName"].ToString(), dr["TMid"].ToString()));
                }
            }
        }
    }

    private void InitializeComponent(bool action)
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WorkTimeN_WorkOnTypeGroup));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = action;
        this.WMaster.AlwaysClose = false;
        this.WMaster.DataCompressed = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "SWorkTime.WorkOnGroup";
        this.WMaster.ServerModify = true;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    protected void Search_Click(object sender, EventArgs e)
    {
        string strDep = Depart.SelectDepmanetId;
        if (strDep == "0")
        {
            strDep = "";
        }
        else
        {
            strDep = "And Employees.DepartmentId like ('" + strDep + "%')";
        }


        string sname = SelUser.EmpName;
        if (sname != "")
        {
            sname = "And Employees.EmpName like ('%" + sname + "%')";
        }
        else
        {
            sname = "";
        }


        string Status = ddlStatus.SelectedValue;
        if (Status == "-1")
        {
            Status = "";
        }
        else
        {
            Status = " And Employees.EmpStatus = " + Status;
        }

        string TM = ddlWorkOnType.SelectedValue;
        if (TM == "NB")
        {
            TM = " And (WorkTime_WorkOnTypeGroup.TMid='' or WorkTime_WorkOnTypeGroup.TMid is null)";
        }
        else if (TM == "AB")
        {
            TM = "";
        }
        else
        {
            TM = " And WorkTime_WorkOnTypeGroup.TMid='" + TM + "' ";
        }

        InitializeComponent(true);

        WMaster.SetWhere(" 1=1 " + strDep + sname + Status + TM);
        Master.DataSource = WMaster;
    }

    protected void AddEmp_Click(object sender, EventArgs e)
    {
        object[] ret = Srvtools.CliUtils.CallMethod("SWorkTime", "SyncWorkOnGroup", new object[] {});
        if ((bool)ret[1])
        {
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('同步成功');location.href='" + Request.Url.ToString() + "'", true);
        }
    }
}
